<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <p>p----1</p>
  <p>p----2</p>
  <p>p----3</p>
  <p>p----4</p>

  <script>
    class jQuery {
      constructor(selector) {
        let result = document.querySelectorAll(selector)
        let length = result.length
        for (let i = 0; i < length; i++) {
          this[i] = result[i]
        }
        this.length = length
        this.selector = selector
      }

      get(index) {
        return this[index]
      }

      each(fn) {
        for (let i = 0; i < this.length; i++) {
          fn(i, this[i])
        }
      }
      on(type, fn) {
        return this.each((index, item) => {
          item.addEventListener(type, fn, false)
        })
      }
    }
  </script>
</body>

</html>